#import <Foundation/Foundation.h>
#import "MTTetrominosBoard.h"

@implementation MTTetrominosBoard : NSObject

const int WIDTH = 10;
const int HEIGHT = 24;

-(void) clearField
{
	int x, y;
	
	for (x = 0; x < WIDTH; x++)
	{
		for (y = 0; y < HEIGHT; y++)
		{
			_playingField[x][y] = NOPIECE;
		}
	}
}

-(int) getWidth
{
	return WIDTH;
}

-(int) getHeight
{
	return HEIGHT;
}

-(int) getVisibleHeight
{
	return HEIGHT - 4;
}

-(int) getPiece: (int) x : (int) y
{
	if ((x < [self getWidth]) && (x >= 0))
	{
		if ((y < [self getHeight]) && (y >= 0))
			return _playingField[x][y];
	}
	
	return 1; //Piece is occupied;
}

-(void) setPiece: (int) x: (int) y : (int) piece
{
	_playingField[x][y] = piece;
}

-(void) removeLine: (int) line
{
	int y, x;
	for (y = line; y > 0; y--)
	{
		for (x = 0; x < [self getWidth]; x++)
		{
			_playingField[x][y] = _playingField[x][y - 1];
		}
	}
}

@end